﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace MvcHeatloss.Models
{
    [MetadataType(typeof(DoorData))]
    public partial class Door
    {
         public ProjectEntities db = new ProjectEntities();
        
        public Door(double length, double width, string type, string temp)
        {
            DoorArea = CalcHeatoss.CalcArea(length , width);
            DoorType = type;
            DoorUValue = (double)db.UValues.Where(d => d.Description == type).Select(u => u.UValue1).First();
            DoorTemp = Int32.Parse(temp);
            DoorHeatloss = CalcHeatoss.FabricHeatloss(this.DoorUValue, this.DoorArea, this.DoorTemp);
        }
        public Door(): base()
        {
        }

        public string DoorType { get; set; }

        public int DoorTemp { get; set; }

        public double DoorUValue { get; set; }

        public double DoorArea { get; set; }

        double doorHeatloss;
        public double DoorHeatloss 
        {
            get
            {
                return doorHeatloss;
            }
            set
            {
                doorHeatloss = CalcHeatoss.FabricHeatloss(this.DoorUValue, this.DoorArea, this.DoorTemp);
            }
        }
    }
    public class DoorData
    {
        [Required(ErrorMessage = "You must enter a Door Width")]
        [Display(Name = "Door Width")]
        public decimal Width { get; set; }

        [Required(ErrorMessage = "You must enter a Door Height")]
        [Display(Name = "Door Height")]
        public decimal Height { get; set; }

    }
}